package day05.JavaCodeHomework;
import java.util.Random;
public class AdvancedPractice {
    public static void main(String[] args) {
        //1. 利用for循环计算：求数字1到100之内，所有偶数的和，并输出
            //第一遍:
                /*
                int sum = 0;
                for (int i = 2; i <= 100; i+=2) {
                    if(i % 2 == 0) {
                        sum += i;
                    }
                }
                System.out.println("sum=" + sum);
                 */

            //第二遍:
                /*
                int sum = 0;
                for (int i = 2; i <= 100; i+=2) {
                        sum += i;
                }
                System.out.println("sum=" + sum);
                 */

            //第三遍:
                /*
                int sum = 0;
                for (int i = 2; i <= 100; i+=2){
                    sum += i;
                }
                System.out.println(sum);
                 */

        //Q2. 利用for循环计算：求8的阶乘，并输出
            //第一遍:
                /*
                int num1 = 1;
                for (int i = 1; i <= 8; i++) {
                    num1 *= i;
                }
                System.out.println(num1);
                 */
            //第二遍:
                /*
                int num2 = 1;
                for(int i = 1; i <= 8; i++) {
                    num2 *= i;
                }
                System.out.println(num2);
                 */

        //Q3. 利用for循环计算：打印字符*组成的直角三角形，输出结果如下所示：
            //第一遍:
                /*
                for(int Line1 = 1; Line1 <= 6; Line1++) {
                    for(int Row1 = 1; Row1 <= 2 * Line1 - 1; Row1++) {
                        System.out.print("*");
                    }
                    System.out.println();
                }
                 */
            //第二遍:
                /*
                for(int Line2 = 1; Line2 <= 6; Line2++) {
                    for (int Row2 = 1; Row2 <= 2 * Line2 - 1; Row2++) {
                        System.out.print("*");
                    }
                    System.out.println();
                }
                 */

        //Q4.  定义数组，包含10个元素，随机生成数据(范围自拟)，查找最大值和最小值，并输出
            //第一遍:
                Random rand1 = new Random();
                int[] arr1 = new int[10];
                int min1 = arr1 [0];
                int max1 = arr1 [0];
                for(int i = 0; i < arr1.length; i++) {
                    arr1[i] = rand1.nextInt(100);

                    if(arr1[i] > max1) {
                        max1 = arr1[i];
                    } else if(arr1[i] < min1) {
                        min1 = arr1[i];
                    }
                    System.out.println(arr1[i]);
                }
                System.out.println(max1);
                System.out.println(min1);
    }
}
